// package/pages/spendingDetail/spendingDetail.js
let myRequest = require('../../../common/script/myRequest.js');
let api = require('../../../common/script/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    billpayment: [],
    billsales: [],
    moneyType: true
  },
  getData(id) {
    const that = this;
    let data = {
      token: wx.getStorageSync('token'),
      identify: id
    }
    wx.showLoading({
      title: '加载中...',
    })
    myRequest.EasyHttp.post(api.reqUrls.getOfflinePayDetail, data).then(res => {
      wx.hideLoading();

      if (res.data.status == 1) {
        res.data.result.orderDetail.billsales.forEach(item => {
          item.quantity = Math.abs(item.quantity)
        })
        let money = 0
        res.data.result.orderDetail.billpayment.forEach(item => {
          money += item.money
        })
        that.setData({
          moneyType: money > 0 ? true : false,
          billpayment: res.data.result.orderDetail.billpayment,
          billsales: res.data.result.orderDetail.billsales,
        })
      } else {
        wx.showModal({
          content: res.data.msg,
          showCancel: false,
          confirmText: '我知道了',
          confirmColor: '#ff5151',
          success(e) {}
        })
      }
    }).catch(err => {
      console.log(err)
      wx.showToast({
        title: '服务器错误',
        icon: 'error',
        duration: 2000
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this;
    that.getData(options.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage() {

  // }
})